﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using TM.QWeibo.SDK.Objects;

namespace TM.QWeibo.SDK.API
{
    /// <summary>
    /// 数据更新
    /// </summary>
    public class UpdateCount: RequestBase
    {
        /// <summary>
        /// 根据授权对象实例化
        /// </summary>
        /// <param name="oauth"></param>
        public UpdateCount(OAuth oauth)
            : base(oauth)
        { }

        private const string requestUrl = "http://open.t.qq.com/api/info/update";

        /// <summary>
        /// 检查更新数据，不至0
        /// </summary>
        /// <param name="callback"></param>
        public void Check(Action<SDK.Objects.ResponseDataBase<SDK.Objects.UpdateCount>> callback) {

            var parameters = new Parameters();
            parameters.Add("format", this.ResponseDataFormat.ToString().ToLower());
            parameters.Add("op", 0);
            GetData(requestUrl, parameters, (json) => {
                var obj = Util.JsonToObject<ResponseDataBase<SDK.Objects.UpdateCount>> (json);
                callback(obj);
            });
        }

        /// <summary>
        /// 检查更新数据，至0
        /// </summary>
        /// <param name="type">至0位</param>
        /// <param name="callback"></param>
        public void Check(SDK.Objects.UpdateCount.ECountType type, Action<SDK.Objects.ResponseDataBase<SDK.Objects.UpdateCount>> callback)
        {

            var parameters = new Parameters();
            parameters.Add("format", this.ResponseDataFormat.ToString().ToLower());
            parameters.Add("op", 1);
            parameters.Add("type", type.GetHashCode());
            GetData(requestUrl, parameters, (json) =>
            {
                var obj = Util.JsonToObject<ResponseDataBase<SDK.Objects.UpdateCount>>(json);
                callback(obj);
            });
        }

        /// <summary>
        /// 指定位清0
        /// </summary>
        /// <param name="type"></param>
        public void Clear(SDK.Objects.UpdateCount.ECountType type)
        { 
            var parameters = new Parameters();
            parameters.Add("format", this.ResponseDataFormat.ToString().ToLower());
            parameters.Add("op", 1);
            parameters.Add("type", type.GetHashCode());
            GetData(requestUrl, parameters, null);
        }

    }
}
